package com.neutech.controller;

import com.google.gson.Gson;
import com.neutech.service.BusinessService;
import com.neutech.service.impl.BusinessServiceImpl;
import com.neutech.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/business/search")
public class BusinessSearchByNameServlet extends HttpServlet {

    private BusinessService businessService = new BusinessServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String  businessName = req.getParameter("businessName");

        PrintWriter out = resp.getWriter();

        Gson gson = new Gson();

        if (businessName == null) {
            out.print(gson.toJson(ResultVO.error(1,"businessName不能为空")));
            out.close();
            return;
        }

        out.print(gson.toJson(businessService.search(businessName)));

        out.close();
    }
}
